package com.wang.springbootinit.controller;

import cn.hutool.core.util.ObjectUtil;
import com.wang.springbootinit.common.BaseResponse;
import com.wang.springbootinit.common.ErrorCode;
import com.wang.springbootinit.common.ResultUtils;
import com.wang.springbootinit.exception.BusinessException;
import com.wang.springbootinit.model.param.IntegralOperateParam;
import com.wang.springbootinit.service.IntegralService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 积分入口
 */
@RestController
@RequestMapping("/integral")
@Slf4j
public class IntegralController {
    @Resource
    private IntegralService integralService;

    /**
     * @SEE  两积分兑换一次调用次数
     */

    /**
     * 签到
     * @param request
     * @return
     */
    @PostMapping("/signIn")
    public BaseResponse<Boolean> signIn(HttpServletRequest request){
        return ResultUtils.success(integralService.signIn(request));
    }

    /**
     * 兑换积分
     * @param request
     * @return
     */
    @PostMapping("/exchange")
    public  BaseResponse<Boolean> exchange(@RequestBody IntegralOperateParam param, HttpServletRequest request){
        if(ObjectUtil.isNull(param)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return ResultUtils.success(integralService.exchange(param,request));
    }
}
